<script setup>
import {ref,reactive} from 'vue'
import { muajax,$message } from '@/common'
import { useStore } from 'vuex'
const store = useStore();
const data		=	reactive({});//数据
let param		=	reactive({});//参数
const visible	=	ref(false);//显示
const forms		=	ref();//表单ref
const loading	=	ref(false);//提交中

// 提交数据 待开发：修改自己的信息后更新登录缓存
function send(){
	forms.value.validate().then(async ()=>{
		if(data.newpassword=='123456'){
			$message.error('不可使用初始密码作为密码使用')
			return;
		}
		loading.value=true;
		let rs = await muajax.resetpsd(data);
		loading.value=false;
		if(rs.code==1){
			store.dispatch('setuserpsd');
			$message.success(rs.msg);
			visible.value=false;
		}
	}).catch(err=>{
		console.log('验证不通过');
		// this.$errorFocus(err);
	})
}
// 显示控制
function show(show,pms){
    visible.value=show;
}
function recheckpasword(rule, value, callback){
	if(data.newpassword!=data.reuse){
		callback(new Error('密码输入不一致'));
	}
	callback()
}
// 对外导出
defineExpose({
	show
})
</script>
<template>
    <a-modal
		v-model:visible="visible"
		width="400px"
		title="修改密码"
		:maskClosable="false"
		@ok="send"
		cancelText="取消"
		okText="提交"
		:confirmLoading="loading"
	>
		<a-form
		ref="forms"
		:model="data"
		>
			<a-form-item
				label="原密码"
				name="password"
				:labelCol="{span:8}"
				:rules="[{ required: true, message: '请输入密码' }]"
			>
				<a-input-password
					size="large"
					placeholder="请输入"
					v-model:value="data.password"
				>
					<template #prefix>
						<LockOutlined />
					</template>
				</a-input-password>
			</a-form-item>
			<a-form-item
				label="新密码"
				name="newpassword"
				:labelCol="{span:8}"
				:rules="[{ required: true, message: '请输入密码' }]"
			>
				<a-input-password
					size="large"
					placeholder="请输入"
					v-model:value="data.newpassword"
				>
					<template #prefix>
						<LockOutlined />
					</template>
				</a-input-password>
			</a-form-item>
			<a-form-item
				label="再次输入新密码"
				name="reuse"
				:labelCol="{span:8}"
				:rules="[{asyncValidator:recheckpasword,trigger: 'blur'}]"
			>
				<a-input-password
					size="large"
					placeholder="请输入"
					v-model:value="data.reuse"
				>
					<template #prefix>
						<LockOutlined />
					</template>
				</a-input-password>
			</a-form-item>
		</a-form>
	</a-modal>
</template>
<style lang="less" scoped>

</style>